/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controlSystem;

import agent.Brain;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Lucky
 */
public class ControlSystem {
    private ArrayList <Brain> arrayOfBrains;
    private int[] lensToPurpose;
    static ControlSystem CS = null;

    public static ControlSystem getInstance(){
        if(CS == null)
            CS = new ControlSystem();
        return CS;
    }

    public void askedDistanceToPurpose(){
        lensToPurpose = new int[arrayOfBrains.size()];
        Iterator it = arrayOfBrains.iterator();
        int i=0;
        while(it.hasNext()){
            Brain b = (Brain) it.next();
            lensToPurpose[i] = (b.getRoute()).length;
        }
    }

    public void addBrainToControlSystem(Brain brain){
        arrayOfBrains.add(brain);
        askedDistanceToPurpose();
    }

    public void changePurposeToAgent(int index, float x, float y){
        Brain b = arrayOfBrains.get(index);
        b.setToX(x);
        b.setToY(y);
    }

}
